#include "myvideosurface.h"
#include <QDebug>

MyVideoSurface::MyVideoSurface(QObject *parent)
    : QVideoSink{parent}{
    connect(this, &MyVideoSurface::videoFrameChanged, this, &MyVideoSurface::present);
}


bool MyVideoSurface::present(const QVideoFrame &frame){
    qDebug() << "获取到相机视频帧";
    if(!frame.isValid())
        return false;
    if(frame.isMapped()){
        emit frameAvailable(frame);
    }else{
        QVideoFrame f(frame);
        f.map(QVideoFrame::ReadOnly);
        emit frameAvailable(f);
    }
    return true;
}
